package erp.server.order.controller;


import erp.server.base.response.JsonResult;
import erp.server.base.response.StatusCode;
import erp.server.order.entity.dto.UseResource;
import erp.server.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单服务
 */
@RestController
@RequestMapping("/isms/usage")
public class OrderController {
    @Autowired
    OrderService orderService;

    /**
     * 使用或预定
     * @param useResource 当开始时间为null便是使用  有开始时间为预定
     */
    @PostMapping("/isms/order/create")
    public JsonResult useResource(UseResource useResource){
        orderService.use(useResource);
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }

    @GetMapping("/isms/order/select")
    public JsonResult select(String userID,String orderID){
        Object data = null;
        if (userID != null) {
            data = orderService.selectByUserID(userID);
        }
        if (orderID != null) {
            data = orderService.selectByOrderID(orderID);
        }
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
}
